import { MutationTree } from 'vuex'

import { LangType } from '@/locales'
import { AppState } from '@/types/app.state'
import { ModuleEnum } from '@/enums/module.enum'
import {
  APP_LANGUAGE,
  TOGGLE_SIDER_COLLAPSED,
  TOGGLE_MODULE,
  ACCOUNT_EXPIRE_REMIND
} from '@/enums/mutation-types'

const initState: AppState = {
  lang: 'zh',
  siderCollapsed: false,
  locales: ['zh', 'en'],
  module: ModuleEnum.Console,
  expireRemind: true
}

export const state = () => ({ ...initState })

export const mutations: MutationTree<AppState> = {
  [APP_LANGUAGE] (state, lang: LangType) {
    if (state.locales.includes(lang)) {
      state.lang = lang
    }
  },
  [TOGGLE_SIDER_COLLAPSED] (state, collapsed: boolean) {
    state.siderCollapsed = collapsed
  },
  [TOGGLE_MODULE] (state: AppState, module: ModuleEnum) {
    state.module = module
  },
  [ACCOUNT_EXPIRE_REMIND] (state, remind: boolean) {
    state.expireRemind = remind
  }
}
